package logic

import (
	"context"
	"fmt"
	"he-ma/HeMarpc/heMarpc"
	"he-ma/HeMarpc/internal/svc"
	"he-ma/models"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopShowLogic {
	return &ShopShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 查询
func (l *ShopShowLogic) ShopShow(in *heMarpc.ShopShowRequest) (*heMarpc.ShopShowResponse, error) {
	// todo: add your logic here and delete this line

	var shop models.Shop
	models.DB.Debug().Where("id = ?", in.ShopId).Find(&shop)
	if shop.ID == 0 {
		return nil, fmt.Errorf("当前商品不存在")
	}

	return &heMarpc.ShopShowResponse{
		Title:   shop.Title,
		Price:   float32(shop.Price),
		Profile: shop.Profile,
	}, nil
}
